package cn.ubeta.b2c.api;

import cn.ubeta.b2c.bean.LogisticsInfo;
import cn.ubeta.b2c.bean.OrderDetailInfo;
import cn.ubeta.b2c.bean.OrderInfo;
import cn.ubeta.b2c.utils.AppConfig;
import cn.ubeta.b2c.utils.NetworkCallback;
import cn.ubeta.b2c.utils.NetworkHelper;

import java.util.List;

/**
 * Created by denny on 16/9/5.
 */

public class ApiOrder {

    private static final String PATH = "/order";

    /**
     * 获取订单信息
     * @param type
     * @param cb
     */
    public static void getOrder(int type, int page, NetworkCallback<List<OrderInfo>> cb) {
        //List<OrderInfo> test = OrderInfo.getTestData();
        List<OrderInfo> test = AppConfig.getOrders();
        if (test != null) {
            cb.onResponse(test);
        } else {
            //String url = String.format("/list?type=%s&page=%d", type, page);
            //NetworkHelper.call(PATH + url, cb);
            List<OrderInfo> data = AppConfig.getOrders();
            cb.onResponse(data);
        }
    }

    /**
     * 获取订单详细信息
     * @param orderId
     * @param cb
     */
    public static void getOrderDetail(int orderId, NetworkCallback<OrderDetailInfo> cb) {
        OrderDetailInfo test = OrderDetailInfo.getTestData();
        if (test != null) {
            cb.onResponse(test);
        } else {
            String url = String.format("/detail?orderId=%d", orderId);
            NetworkHelper.call(PATH + url, cb);
        }
    }

    /**
     * 获取订单物流信息
     * @param orderId
     * @param cb
     */
    public static void getLogistics(long orderId, NetworkCallback<LogisticsInfo> cb) {
        LogisticsInfo test = LogisticsInfo.getTestData();
        if (test != null) {
            cb.onResponse(test);
        } else {
            String url = String.format("/getLogistics?orderId=%d", orderId);
            NetworkHelper.call(PATH + url, cb);
        }
    }
}
